package com.nutricia.core.service.convertor;

import com.nutricia.common.dal.persistant.SystemRole;
import com.nutricia.core.model.domain.SystemRoleDO;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 系统角色对象转换器
 *
 * @author: huangsheng
 * @date: 2017/10/20
 */
public class SystemRoleServiceConvertor {

   /**
    * 将 systemRole SystemRoleDO
    *
    * @author: huangsheng
    * @date: 2017/10/24 上午10:48
    */
    public static SystemRoleDO convertToSystemRoleDO(SystemRole systemRole) {
        if (null == systemRole) {
            return null;
        }
        SystemRoleDO systemRoleDO = new SystemRoleDO();
        systemRoleDO.setId(systemRole.getId());
        systemRoleDO.setRoleCode(systemRole.getRoleCode());
        systemRoleDO.setRoleName(systemRole.getRoleName());
        return systemRoleDO;
    }

    /**
     * 将SystemUsers转换为SystemUserDOs
     *
     * @author: huangsheng
     * @date: 2017/10/20 下午2:00
     */
    public static List<SystemRoleDO> convertToSystemRoleDOs(List<SystemRole> systemRoles) {
        List<SystemRoleDO> systemRoleDOS = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(systemRoles)) {
            systemRoles.forEach(systemRole -> {
                systemRoleDOS.add(SystemRoleServiceConvertor.convertToSystemRoleDO(systemRole));
            });
            return systemRoleDOS;
        }
        return Collections.emptyList();
    }

}
